package com.web;


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.entity.Document;
import com.entity.Employee;
import com.entity.File;
import com.entity.FileType;
import com.entity.Ideal;
import com.service.DocumentService;
import com.service.FileService;
import com.service.FileTypeService;
import com.service.IdealService;

public class Is extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Employee employee=(Employee)request.getSession().getAttribute("employee");
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out=response.getWriter();
		
		String id=request.getParameter("id");
		String type=request.getParameter("type");
		if ("document".equals(type)) {
			DocumentService documentService=new DocumentService();
			Document document=documentService.getById(id);
			if (employee.getId().equals(document.getEmployeeid())) {
				out.print("ok");
			}else {
				out.print("error");
			}
		}else if ("file".equals(type)) {
			FileService fileService=new FileService();
			File file=fileService.getById(id);
			if (employee.getId().equals(file.getEmployeeid())) {
				out.print("ok");
			}else {
				out.print("error");
			}
		}else if ("folder".equals(type)) {
			FileTypeService fileTypeService=new FileTypeService();
			FileType fileType=fileTypeService.getById(id);
			if (employee.getId().equals(fileType.getEmployeeid())) {
				out.print("ok");
			}else {
				out.print("error");
			}
		}else if ("ideal".equals(type)) {
			IdealService idealService=new IdealService();
			Ideal ideal=idealService.getById(id);
			if (employee.getId().equals(ideal.getEmployeeid())) {
				out.print("ok");
			}else {
				out.print("error");
			}
		}
		
		out.flush();
		out.close();
	}

}
